/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;

/**
 *
 * @author italo
 */
@Entity
public class Login extends AbstractEntity{
    
    @Column(nullable = false)
    private String userName;
    
    @Column(nullable = false)
    private String password;
    
    @OneToOne
    @JoinColumn(name = "person_id", nullable = false)
    private Person person;
    
    public Login() {
    }

    @Override
    public void generateHash(){
        if(getId() == null || getId() == 0L){
            this.setId((this.getPerson() != null) ? this.getPerson().getId() : null);
        }
    }

    public Login(String userName, String password, Person person) {
        this.userName = userName;
        this.password = password;
        this.person = person;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}
